package com.ll.homework;

import java.util.ArrayList;

/**
 * @author 刘龙
 * @version 1.0
 */
public class Homework {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new News("kkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "hhhhhhhhhhhhhhhhhhhhh"));
        arrayList.add(new News("vvvvvvvvvvvvvvvvvvvvvvvvvvvvv", "lllllllllllllllllllll"));

        int size = arrayList.size();
        for (int i = size - 1; i >= 0; i--) {
            News news = (News) arrayList.get(i);
            System.out.println(processTitle(news.getTitle()));

        }
    }

    /**
     * 对字符串进行处理,只截取前15个字符,并且末尾加上...
     *
     * @param title
     * @return
     */
    public static String processTitle(String title) {

        if (title == null) {
            return " ";
        }

        if (title.length() > 15) {
            return title.substring(0, 15) + "...";
        } else {
            return title + "...";
        }

    }
}

class News {
    private String title;
    private String content;

    public News(String title, String content) {
        this.title = title;
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "News{" +
                "title='" + title + '\'' +
                ", content='" + content + '\'' +
                '}';
    }
}
